package main

import (
	"fmt"
	"sync"
)

type detectBase struct {
	dstIP      string
	timeout    int
	interval   int
	pktNum     int
	pktLen     int
	vpn        string
	sndCnt     int
	rcvCnt     int
	timeoutCnt int
	// ...
}

type DetectItf interface {
	sndPkt()
	rcvPkt()
}

type Ping struct {
	detectBase // noname struct inherit

	minTrip int
	aveTrip int
	maxTrip int
}

type TraceRt struct {
	detectBase
	hops []struct {
		hopIdx int
		path   string
		isConn bool
	}
}

func echo(s string) {
	fmt.Println(s)
}

// use interface to storage the detect task
// ping and tracert all implement the interface
var DetectPool []DetectItf

// seq id auto increment
type seqKey struct {
	srcIP  string
	dstIP  string
	vpn    string
	pktLen int
}

func fetchAndIncreSeq(key seqKey) int {
	item := SeqIDPool.Load(key)
	SeqIDPool.Store(key, item+1)
	return item
}

// srcIP dstIP and vpn will use not the same seq id in pool
// map is not threadsafe
// sync.RWMut or sync.map
// var SeqIDPool map[seqKey]int
// SeqIDPool.data[key]++

// var SeqIDPool struct {
// 	data map[seqKey]int
// 	lock sync.RWMutex
// }

var SeqIDPool sync.Map

// recv pkt should id tracert or ping type
// ping and tracert will share the pool
func (t *TraceRt) sndPkt() {
	echo("tracert snd act!")
}

func (t *TraceRt) rcvPkt() {
	echo("tracert rcv act!")
}
